﻿
using System ;


namespace MskEdit.Msk.Representation
{

    public class IntField {
    
        private StringField stringField_ ;
 
 
        private IntField( StringField stringField ) {
            stringField_ = stringField ;
        }
            
            
        public int? TryFrom( string line, int? fallbackValue ) { 
        
            string intStr = stringField_.TryFrom( line, fallbackValue.ToString() ) ;
            
            int value = 0 ;            
            if ( ! int.TryParse( intStr, out value ) )
                return fallbackValue ;
            
            return value ;
        }
        
        
        public string TryInsert( string line, int value, string fallbackValue ) {
            return stringField_.TryInsert( line, value.ToString(), fallbackValue ) ;
        }
        
        
        static public IntField Len       = new IntField( StringField.Len ) ;
        static public IntField Yk        = new IntField( StringField.Yk ) ;
        static public IntField Xk        = new IntField( StringField.Xk ) ;
        static public IntField Decimals  = new IntField( StringField.Decimals ) ;
        static public IntField PageCode  = new IntField( StringField.PageCode ) ;
        static public IntField FunCode   = new IntField( StringField.FunCode ) ;
    }
}
